package com.kmxd.ams.core.common.enums;

import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 汇总函数类型
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum SummaryTypeEnum {
  /** 最大值 */
  MAX("max", "最大值"),
  MIN("min", "最小值"),
  AVG("avg", "平均值"),
  SUM("sum", "合计"),
  COUNT("count", "计数"),
  ;

  private String func;
  private String desc;

  public static SummaryTypeEnum convert(String func) {
    return Arrays.stream(values())
        .filter(x -> x.func.equals(func))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + func));
  }
}
